/********************************************************************
Replication Data for: "Talking Politics in a Polarized America (Political Behavior)"
********************************************************************/

use "PanelStudy.dta", clear

forvalues i = 1/2 {
* perceived polarization
recode PP1_`i' (1=1) (2=2) (3=3) (4=4) (else=.), gen(percpol1_`i')
recode PP2_`i' (1=1) (2=2) (3=3) (4=4) (else=.), gen(percpol2_`i')
recode PP3_`i' (1=4) (2=3) (3=2) (4=1) (else=.), gen(percpol3_`i')
recode PP4_`i' (1=4) (2=3) (3=2) (4=1) (else=.), gen(percpol4_`i')

* self-censorship 
recode SCA_`i' SCB_`i' SCC_`i' (1=1) (2=2) (3=3) (4=4) (5=5) (else=.)

* political interest
recode Q16_`i' (1=4) (2=3) (3=2) (4=1) (else=.), gen(polinterest_`i')

* feeling thermometer
recode THERM3_`i' THERM4_`i' (777 998=.)

* perceived civility
recode CIVIL1_`i' (1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1) (else=.), gen(civil1_`i')  
recode CIVIL3_`i' (1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1) (else=.), gen(civil3_`i')  
recode CIVIL5_`i' (1=10) (2=9) (3=8) (4=7) (5=6) (6=5) (7=4) (8=3) (9=2) (10=1) (else=.), gen(civil5_`i')
recode CIVIL2_`i' (77 98 99 =.), gen(civil2_`i')  
recode CIVIL4_`i' (77 98 99 =.), gen(civil4_`i')    

* issue attitude  
recode IM1_`i' (1=5) (2=4) (3=3) (4=2) (5=1) (77 98 99=.), gen(immi1_`i')
recode IM2_`i' (77 98 99=.), gen(immi2_`i') 
recode IM3_`i' (77 98 99=.), gen(immi3_`i') 
recode HC1_`i' (1=5) (5=1) (4=2) (2=4) (3=3) (77 98 99=.), gen(hcare_`i')
recode TSN1_`i' (1=5) (5=1) (4=2) (2=4) (3=3) (77 98 99=.), gen(spending_`i') 
recode TSN2_`i' (77=.) (98=.) (99=.), gen(taxcut_`i') 
recode TR1_`i' (1=5) (5=1) (4=2) (2=4) (3=3) (77 98 99=.), gen(trade_`i') 
}

forvalues i = 1/2 {
egen immigration_`i'=rowmean(immi1_`i' immi2_`i' immi3_`i')
}

foreach x in immigration_1 immigration_2 {
gen ext`x'=`x'
replace ext`x'=6-ext`x' if ext`x'<3
replace ext`x'=ext`x'-3 
}

foreach x in hcare_1 spending_1 taxcut_1 trade_1 hcare_2 spending_2 taxcut_2 trade_2 {
gen ext`x'=`x'
replace ext`x'=abs(3-`x') 
}

* index
forvalues i = 1/2 {
egen perpola_`i' = rowmean(percpol1_`i' percpol2_`i' percpol3_`i' percpol4_`i')
gen therdiff_`i' = abs(THERM3_`i'-THERM4_`i')
egen uncivil_`i' = rowmean(civil1_`i' civil3_`i' civil5_`i' civil2_`i' civil4_`i')
egen extattitude_`i'=rowmean(extimmigration_`i' exthcare_`i' extspending_`i' exttaxcut_`i' exttrade_`i') 
}

* rescale
foreach var in perpola_1 perpola_2 {
qui sum `var'
gen r`var' = (`var'-1) / (4-1) 
}

foreach var in SCA_1 SCB_1 SCC_1 SCA_2 SCB_2 SCC_2 polinterest_1 polinterest_2 therdiff_1 therdiff_2 uncivil_1 uncivil_2 extattitude_1 extattitude_2 {
qui sum `var'
gen r`var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
}

clonevar rinterest = rpolinterest_1 

* reshape into long form
reshape long perpola_ rSCA_ rSCB_ rSCC_ rperpola_ rpolinterest_ runcivil_ rtherdiff_ rextattitude_, i(rID) j(wave)
xtset rID wave 

eststo m1: xtreg rSCA_ rperpola_ i.wave, fe robust
eststo m2: xtreg rSCA_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave, fe robust
eststo m3: xtreg rSCB_ rperpola_ i.wave, fe robust
eststo m4: xtreg rSCB_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave, fe robust
eststo m5: xtreg rSCC_ rperpola_ i.wave, fe robust
eststo m6: xtreg rSCC_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave, fe robust

* Table 1 
esttab m1 m2 m3 m4 m5 m6, b(%8.3fc) se replace label nogaps noomit nobase order(rperpola_ rextattitude_ rtherdiff_ rpolinterest_ runcivil_ wave)



* Appendix D
eststo m1a: xtreg rSCA_ rperpola_ i.wave i.wave##c.rinterest, fe robust
eststo m2a: xtreg rSCA_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave i.wave##c.rinterest, fe robust
eststo m3a: xtreg rSCB_ rperpola_ i.wave i.wave##c.rinterest, fe robust
eststo m4a: xtreg rSCB_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave i.wave##c.rinterest, fe robust
eststo m5a: xtreg rSCC_ rperpola_ i.wave i.wave##c.rinterest, fe robust
eststo m6a: xtreg rSCC_ rperpola_ rextattitude_ rtherdiff_ runcivil_ rpolinterest_ i.wave i.wave##c.rinterest, fe robust

esttab m1a m2a m3a m4a m5a m6a, b(%8.3fc) se replace label nogaps noomit nobase order(rperpola_ rextattitude_ rtherdiff_ rpolinterest_ runcivil_ wave)


